﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace nRoute.Components.Composition.Adapters
{
    public class EnumerableFuncLocatorAdapter<T> 
        : LocatorAdapterBase<T, IEnumerable<Func<T>>>
        where 
            T : class
    {
        public EnumerableFuncLocatorAdapter()
            : base((b, s) =>
            {
                // note_ we are ignoring the string "s" type sent in
                if (b.ResourceCatalog.IsResourceable<T>())
                {
                    return ((IResourceCatalogEx)b.ResourceCatalog).GetResourceCatalog<T>().Select((l) => new Func<T>(() => (T)l.GetResource(b)));
                }
                else
                {
                    return Enumerable.Empty<Func<T>>();
                }
            }) { }
    }
}